/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webaccess.retailws.Util;

import com.webaccess.retailws.Bean.CategoryBean;
import com.webaccess.retailws.Delegate.CategoryDelegate;

import org.apache.struts.upload.FormFile;

/**
 *
 * @author Owner
 */
public class CategoryUtil {

    CommonUtil commUtil = null;
    CategoryBean categBean = null;
    CategoryDelegate categDelegate = null;

    public CategoryUtil() {
        commUtil = new CommonUtil();
    }

    public String saveCategory(Long categoryId, String categoryName, String categoryTitle, String categoryDesc, Long categoryStatusId, String categoryImageName, Long parentCategoryId, int mainCategory) {
        categDelegate = new CategoryDelegate();
        String SUCCESS = "";
        try {
            categBean = new CategoryBean();
            categBean.setCategoryId(categoryId);
            categBean.setCategoryDesc(categoryDesc);
            categBean.setCategoryImageName(categoryImageName);
            categBean.setCategoryName(categoryName);
            categBean.setCategoryStatusId(categoryStatusId);
            categBean.setCategoryTitle(categoryTitle);
            categBean.setParentCategoryId(parentCategoryId);
            categBean.setMainCategory(mainCategory);
            boolean isCategorySaved = categDelegate.saveCategory(categBean);
            if (categoryId == null) {
                if (isCategorySaved == false) {
                    SUCCESS = "savecategoryfailure";
                } else {
                    SUCCESS = "categorysuccess";
                }
            } else {
                if (isCategorySaved == false) {
                    SUCCESS = "updatecategoryfailure";
                } else {
                    SUCCESS = "categorysuccess";
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return SUCCESS;
        }
    }

    public String uploadFile(FormFile categoryImage, String filePath) {
        return commUtil.uploadFile(categoryImage, filePath);
    }
}
